#map_print.py
import sys
def setup_printer():
	print sys.argv[0]
	rawmap = sys.argv[1]
	htmlm = ''
	if rawmap.endswith('.pymap'):
		htmlm = rawmap[:-6] +'.html'
	printer(htmlm)
setup_printer()
def printer(htmlmap):
	rm = open(rawmap, "r")
	hm = open(htmlmap, "a")
	hm.write("<!DOCTYPE html>\n<html lang=\"en\">\n<head>\n<meta charset=\"utf-8\">\n<link rel=\"stylesheet\" type=\"text/css\" href=\"map_table.css\" />\n</head>\n<body><table>\n")
	hm_cur_line = "<tr>"
	for line in rm:
		for n in line:
			if (n !='\n'):
				c = int(n)
			if c == 0:
				hm_cur_line = hm_cur_line + "<td class=\"r\"> </td>"#ravine
			elif c == 1:
				hm_cur_line = hm_cur_line + "<td class=\"f\"> </td>" #flat
			elif c == 2:
				hm_cur_line = hm_cur_line + "<td class=\"h\"> </td>"#hill
			elif c == 3:
				hm_cur_line = hm_cur_line + "<td class=\"m\"> </td>"#mountain
			elif c == 4:
				hm_cur_line = hm_cur_line + "<td class=\"c\"> </td>"#cliff
		hm_cur_line = hm_cur_line + "</tr>\n"
		hm.write(hm_cur_line)
		hm_cur_line = "<tr>"
	rm.close()
	hm.write("</table>\n</body>\n</html>")
	hm.close()
	return
